Crate micromath[][src]

Embedded-friendly (i.e. #![no_std]) math library featuring fast, safe floating point approximations for common arithmetic operations, as well as 2D and 3D vector types, statistical analysis functions, and quaternions.

Floating point approximations

micromath supports approximating many arithmetic operations on f32 using bitwise operations, providing great performance and small code size at the cost of precision. For use cases like graphics and signal processing, these approximations are often sufficient and the performance gains worth the lost precision.

These approximations are provided by the micromath::F32Ext trait which is impl’d for f32, providing a drop-in std-compatible (sans lost precision) API.

use micromath::F32Ext;

let n = 2.0.sqrt();
assert_eq!(n, 1.5); // close enough

Unused import warnings when linking std

Since the F32Ext trait provides methods which are already defined in std, in cases where your crate links std the F32Ext versions of the same methods will not be used, in which case you will get an unused import warning for F32Ext.

If you encounter this, add an #[allow(unused_imports)] above the import.

#[allow(unused_imports)]
use micromath::F32Ext;

Vector types

See the vector module for more information on vector types.

The following vector types are available, all of which have pub x and pub y (and on 3D vectors, pub z) members:

Rust2D3D
i8I8x2I8x3
i16I16x2I16x3
i32I32x2I32x3
u8U8x2U8x3
u16U16x2U16x3
u32U32x2U32x3
f32F32x2F32x3

Statistical analysis

See the statistics module for more information on statistical analysis traits and functionality.

The following traits are available and impl’d for slices and iterators of f32 (and can be impl’d for other types):

  • Mean - compute arithmetic mean with the mean() method
  • StdDev - compute standard deviation with the stddev() method
  • Trim - cull outliers from a sample slice with the trim() method.
  • Variance - compute variance with the `variance() method

Quaternions

See the quaternion module for more information.

Re-exports

pub use crate::quaternion::Quaternion;
pub use crate::vector::Vector;
pub use crate::vector::VectorExt;
pub use generic_array;

Modules

quaternionquaternion

Quaternions are a number system that extends the complex numbers which can be used for efficiently computing spatial rotations.

statisticsstatistics

Statistical analysis support.

vectorvector

Algebraic vector types generic over a number of axes and a component type.

Traits

F32Ext

f32 extension providing various arithmetic approximations and polyfills for std functionality.